package com.ruoyi.test.exception;

import com.ruoyi.test.domain.common.Result;
import com.ruoyi.test.domain.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class MyGlobalExceptionHandler {

    //全局异常处理
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }

    //自定义异常处理
    @ExceptionHandler(MyGuiguException.class)
    @ResponseBody
    public Result error(MyGuiguException e) {
        return Result.build(null, e.getResultCodeEnum());
    }

}

